package com.shareyi.simpleserver.handler;

import java.io.IOException;
import java.net.Socket;
import java.util.List;

import com.shareyi.joywindow.JoyWindowData;
import com.shareyi.simpleserver.core.HttpRequest;
import com.shareyi.simpleserver.core.HttpResponse;
import com.shareyi.simpleserver.core.SimpleHttpServer;
import com.shareyi.simpleserver.servlet.Filter;
import com.shareyi.simpleserver.servlet.FilterChain;
import com.shareyi.simpleserver.servlet.ServletException;
import com.shareyi.simpleserver.servlet.SimpleFilterChain;
import com.shareyi.simpleserver.servlet.WebApplication;

public  class FilterHander implements Handler {

	private static FilterHander filterHander;
	
	private WebApplication webApplication;
	
	public void doHandle(Socket connection, HttpRequest request,
			HttpResponse response) throws IOException, ServletException {
		this.webApplication=SimpleHttpServer.getServerInstance().getWebApplication();
		List<Filter> filterList= webApplication.getFilterListByRequest(request);
		FilterChain filterChain=new SimpleFilterChain(filterList);
		filterChain.doFilter(request, response);
	}

	
	
	
	public static  Handler getSingleHandler() {
		if(filterHander==null){
			filterHander=new FilterHander();
		}
		return filterHander;
	}




	public void setWebApplication(WebApplication webApplication) {
		this.webApplication=webApplication;
	}
	

}
